package it.rap.applications.birt.report.accounts.core;

import it.rap.applications.container.IContainerPage;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;

public class SummarySpendReviewForYear extends CustomReport implements IContainerPage {

	private Browser browser;	
	private Combo	combo;
 	/**
	 * @wbp.parser.entryPoint
	 */
	public void wBuilderEntriPoint(Composite parent){
		Composite contentComp = new Composite(parent, SWT.NONE);
		contentComp.setToolTipText("Seleziona l'anno da analizzare");
		this.createControl(contentComp);
	}
	
	@Override
	public void createControl(Composite parent) {
		GridLayout gl_contentComp = new GridLayout( 1, false );
		parent.setLayout( gl_contentComp );
	
		combo = new Combo(parent, SWT.READ_ONLY);
		combo.addSelectionListener(new SelectionAdapter() {
			private static final long serialVersionUID = 7688017045281095117L;

			@Override
			public void widgetSelected(SelectionEvent e) {
				try {
					HTMLView htmlView = new HTMLView("reportTest.rptdesign");	
					htmlView.createReport( combo.getText() );
					String reportHtml = htmlView.doReport();
					browser.setText( reportHtml );
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
		combo.setItems(new String[] {"2012", "2013", "2014"});
		combo.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
		combo.select(0);
		
		
		Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new FillLayout(SWT.HORIZONTAL));
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		browser = new Browser( composite, SWT.NONE );
		browser.setSize( parent.getSize().x - 1, parent.getSize().y - 1 );
		
		String reportHtml = "";
		
		try {
			HTMLView htmlView = new HTMLView("reportTest.rptdesign");	
			htmlView.createReport( null );
			reportHtml = htmlView.doReport();
			browser.setText( reportHtml );
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
